package com.ylkj.wx.constant;

import org.apache.commons.lang3.StringUtils;

/**
 * 
 * <p>微信接口返回错误码</p>
 * <p>@Since 2015年1月16日 下午4:39:53</p>
 * @author <a href=luoqi@neusoft.com>罗琦</a>
 */
public enum ErrorType {
    SYSTEM_BUSY("-1","系统繁忙,此时请稍候再试"),
    VALID_ACCESS_TOKEN("0","ok"),
    INVALID_AppSecret_Token("40001","获取access_token时AppSecret错误，或者access_token无效"),
    INVALID_40002("40002", "不合法的凭证类型"),
    INVALID_OPENID("40003","不合法的OpenID"),
    INVALID_40013("40013","不合法的AppID"),
    INVALID_40014("40014"," 不合法的access_token"),
    INVALID_OAUTH_CODE("40029","不合法的oauth_code");

    private String errorCode;
    private String errorMessage;
    
    private ErrorType(String errorCode, String errorMessage) {
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }
    
    public String getErrorCode() {
        return errorCode;
    }
    
    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }
    
    public String getErrorMessage() {
        return errorMessage;
    }
    
    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }
    
    public static String obtainMessage(String errorCode) {
        ErrorType[] errorTypes = ErrorType.values();
        String errorMessage = "";
        for(ErrorType errorType : errorTypes) {
            if(StringUtils.equals(errorType.getErrorCode(), errorCode)) {
                errorMessage = errorType.getErrorMessage();
                break;
            }
        }
        return errorMessage;
    }
}
